from selenium.webdriver.common.by import By
from webAutomation.base.base_page import BasePage, BaseHandle


# 对象层
# 首页页面类
class HomePage(BasePage):
    def __init__(self):
        # 继承父类
        super().__init__()
        # 电柜
        self.electric_cabinet = By.XPATH, "//*[@id='app']/section/aside/ul/li[2]/div/span"
        # 电柜概览
        self.overview_of_electric_cabinet = By.XPATH, "//*[@id='app']/section/aside/ul/li[2]/ul/li/ul/li[1]"
        # 电池
        self.battery = By.XPATH, "//*[@id='app']/section/aside/ul/li[3]/div/span"
        # 电池概览
        self.overview_of_battery = By.XPATH, '//*[@id="app"]/section/aside/ul/li[3]/ul/li/ul/li/span'

    # 查找电柜模块
    def find_electric_cabinet(self):
        return self.find_element(self.electric_cabinet)

    # 查找电柜概览
    def find_overview_of_electric_cabinet(self):
        return self.find_element(self.overview_of_electric_cabinet)

    # 查找电池模块
    def find_battery(self):
        return self.find_element(self.battery)

    # 查找电池概览
    def find_overview_of_battery(self):
        return self.find_element(self.overview_of_battery)


# 操作层
class HomeHandle(BaseHandle):
    def __init__(self):
        # 实例化首页页面类
        self.home_page = HomePage()

    # 点击电柜模块
    def click_electric_cabinet(self):
        return self.home_page.find_electric_cabinet().click()

    # 点击电柜概览
    def click_overview_of_electric_cabinet(self):
        return self.home_page.find_overview_of_electric_cabinet().click()

    # 点击电池模块
    def click_battery(self):
        return self.home_page.find_battery().click()

    # 点击电池概览
    def click_overview_of_battery(self):
        return self.home_page.find_overview_of_battery().click()



# 业务层
class HomeProxy:
    def __init__(self):
        self.home_handle = HomeHandle()

    # 打开电柜概览页面
    def open_overview_of_electric_cabinet(self):
        print("---------open_overview_of_electric_cabinet start...----------")
        # 点击电柜模块
        self.home_handle.click_electric_cabinet()
        # 点击电柜概览
        self.home_handle.click_overview_of_electric_cabinet()
        print("----------open_overview_of_electric_cabinet end...-----------")

    # 打开电池概览页面
    def open_overview_of_battery(self):
        print("---------open_overview_of_electric_battery start...----------")
        # 点击电柜模块
        self.home_handle.click_battery()
        # 点击电柜概览
        self.home_handle.click_overview_of_battery()
        print("----------open_overview_of_electric_battery end...-----------")